package com.mars.miaosha.dao;

import com.mars.miaosha.domain.Goods;
import com.mars.miaosha.domain.MiaoshaGoods;
import com.mars.miaosha.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author MARS
 * @date 2018/5/9
 */
@Mapper
public interface GoodsDao {

    /**
     * 查询商品list
     * @return
     */
    @Select("select t.*,m.ms_price as miaosha_price ,m.stock_count,m.start_date,m.end_date from miaosha_goods m LEFT JOIN ms_goods t on m.goods_id = t.id")
    public List<GoodsVo> getGoodsVoList();

    @Select("select t.*,m.ms_price as miaosha_price ,m.stock_count,m.start_date,m.end_date from miaosha_goods m LEFT JOIN ms_goods t on m.goods_id = t.id where t.id=#{goodsId}")
    GoodsVo getGoodsByGoodsId(long goodsId);

    @Update("update miaosha_goods set stock_count=stock_count -1  where goods_id = #{goodsId}")
    void reduceStock(MiaoshaGoods goods);
}
